/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.rpc.client  
 */
package com.apache.rpc.client;

import com.apache.database.constant.SpringContextLoader;
import com.apache.rpc.ProtocolService;
import com.apache.rpc.entity.Protocol;
import com.apache.rpc.util.JsonEntityParese;

/**
 * description:  通信协议客户端实现
 * @author Hou Dayu 创建时间：2014-10-30  
 * @Copyright(c)2014:
 */
public class ProtocolServiceClient {

	private static ProtocolServiceClient client;

	private ProtocolService service;

	private ProtocolServiceClient() {
		service = (ProtocolService) SpringContextLoader.getBean("protocolAdapter");
	}

	public synchronized static ProtocolServiceClient instance() {
		if (null == client) {
			client = new ProtocolServiceClient();
		}
		return (client);
	}

	public Object doService(Protocol protocol) {
		return service.doService(protocol);
	}

	public <T> T xmlToBean(String xmlStr, Class<T> cls) {
		return JsonEntityParese.instance().toBean(xmlStr, cls);
	}

	public <T> T jsonToBean(String jsonStr, Class<T> cls, Class attrCls) {
		return JsonEntityParese.instance().jsonToBean(jsonStr, cls, attrCls);
	}
}
